package com.jqsoft.launcher.activity;

import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.jqsoft.launcher.R;

public  class WebViewActivity extends JQActivity {
	
	public WebView webView;
	
	@Override
	protected int getContentLayout() {
		return R.layout.webview_layout;
	}

	@Override
	protected void initGui() {
		webView = (WebView) this.findViewById(R.id.webView);
		webView.getSettings().setDefaultTextEncodingName("utf-8");
		webView.getSettings().setJavaScriptEnabled(true);
		webView.requestFocus();
//		webView.getSettings().setUseWideViewPort(true);
//		webView.getSettings().setLoadWithOverviewMode(true);
		webView.setWebChromeClient(new WebChromeClient(){
			@Override
			public void onProgressChanged(WebView view, int progress){
				WebViewActivity.this.setProgress(progress);
			}
			@Override
		    public boolean onJsAlert(WebView view, String url, String message,  
		            JsResult result) {  
		        final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());  
		        builder.setTitle("")  
		                .setMessage(message)  
		                .setPositiveButton("确定", null);  
		        // 禁止响应按back键的事件  
		        builder.setCancelable(false);  
		        AlertDialog dialog = builder.create();  
		        dialog.show();  
		        result.confirm();
		        return true;  
		    }
		});
		webView.setWebViewClient(new WebViewClient(){
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				loadWaitPanel();
				super.onPageStarted(view,url,favicon);
		    }
			public void onPageFinished(WebView view, String url) {
				dismissrogressBar();
				super.onPageFinished(view,url);
		    }
		});
		webView.setOnKeyListener(new View.OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if(keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
					webView.goBack();
					return true;
				}
				return false;
			}
		});
	}

	@Override
	protected void initAction() {
		
	}

	@Override
	protected void initData() {
		
	}
	
}
